home *** CD-ROM | disk | FTP | other *** search
- /*
- IC Link In.c
-
- Main code for accessing the configuration file. This code can be linked in to an application
- (if the component is not available) to provide access to the IC prefs file.
-
- This code represents the lowest-level of access to the config file.
-
- History
- 11/06/95 dhn - Started C port.
- */
-
- /*
- Original pascal comment:
-
- (* File: ICLinkIn.p
- * Generated by: 1.0d4
- * For: IC 1.2
- * On: Monday, 25 September 1995, 19:28:12
- *
- * This file is part of the Internet Configuration system and
- * is placed in the public domain for the benefit of all.
- *)
- */
-
- #include <Components.h>
- #include <AppleTalk.h>
- #include <Folders.h>
- #include <Processes.h>
- #include <Errors.h>
- #include <AppleEvents.h>
- #include <LowMem.h>
-
- #include "IC Types.h"
- #include "IC Keys.h"
-
- #include "IC Resource API.h"
- #include "IC Link In Subs.h"
-
- #define kICOurManufacturer 'JPQE'
- #define kRes_Code 'ICRP'
-
- // Local Prototypes
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- OSErr ICFindFolder(short vRefNum,OSType folderType,Boolean createFolder,short* foundVRefNum,long* foundDirID);
- Boolean ICRCloseIfOpen(ICRRecordPtr inst);
- ICError ValidDirSpec(ICDirSpec* folder);
- OSErr FoundFile(ICDirSpec* folder,short ndx,FSSpec* found_file);
- Boolean ScanFolder(ICRRecordPtr inst,ICDirSpec* folder,FSSpecPtr found_file);
- OSErr FindPrefFolder(ICDirSpec* pref_fold);
- void SetSFCWD(ICRRecordPtr inst);
- ICError GetFile(ICRRecordPtr inst,FSSpecPtr fs);
- ICError PutFile(ICRRecord* inst,FSSpecPtr fs);
- short ICRPermToFSPerm(ICPerm perm);
- ICError ICRCheckInside(ICRRecord* inst);
- ICError ICRForceInside(ICRRecord* inst,ICPerm perm,Boolean* force_info);
- ICError ICRReleaseInside(ICRRecord* inst,Boolean force_info);
- Boolean __URL_SpecStartChar(char ch);
- Boolean __URL_SpecEndChar(char ch);
- ICError ExpandSelection(char* datap,long len,long* selStart,long* selEnd);
- Boolean SpaceTab(char ch);
- Boolean SpaceTabRet(char ch);
- ICError ShrinkSelection(char* datap,long len,long* selStart,long* selEnd);
- ICError StripReturns(Handle urlh);
- void UnpackCopyString(Ptr* p,StringPtr s);
- OSErr UnpackEntry(Handle entries,long pos,ICMapEntry* entry,long* user_length);
- OSErr FastGetEntry(Handle entries,long pos,ICMapEntry* entry);
- void PackCopyString(ICMapEntry* entry,Ptr p,StringPtr s);
- void PackEntry(ICMapEntry* entry,Ptr p,long user_length);
- short GetShort(Ptr P);
- char UpCase(char ch);
- Boolean IsExtensionVar(StringPtr name,StringPtr ext);
-
- Boolean HasResourceFork(const FSSpec* file);
- OSErr EnsureResourceFork(const FSSpec* file);
-
- #ifdef __cplusplus
- }
- #endif
-
- /*
- HasResourceFork
- EnsureResourceFork
-
- The IC pieces have one bug (that I have found). Although they ensure that a file exists when selecting one
- (either through the Find, FindUser, FindGeneral, or SpecifyConfigFile routines), they don't ensure that the
- files have a resource fork. That means that whatever piece is specifying the file *must* get everything right.
-
- HasResourceFork and EnsureResourceFork will check the config file; if it has a resource fork, nothing is done.
- If the file doesn't have a resource fork, one will be added.
- */
- Boolean HasResourceFork(const FSSpec* spec){
- HParamBlockRec pbr;
- OSErr err;
-
- pbr.fileParam.ioCompletion=0;
- pbr.fileParam.ioVRefNum=spec->vRefNum;
- pbr.fileParam.ioFDirIndex=0;
- pbr.fileParam.ioNamePtr=(StringPtr)spec->name;
- pbr.fileParam.ioDirID=spec->parID;
-
- err=PBHGetFInfo(&pbr,false);
- if (err!=noErr)
- return false;
-
- /*
- If a file has a resource fork, even an empty one, a resource map will still exist for the file,
- therefore the ioFlRLgLen (which contains the length of the resource fork) will be some number
- greater than zero if the file has a resource fork.
- */
- return (pbr.fileParam.ioFlRLgLen>0);
- }
-
- OSErr EnsureResourceFork(const FSSpec* spec){
- HParamBlockRec pbr;
- OSErr err;
-
- pbr.fileParam.ioCompletion=0;
- pbr.fileParam.ioVRefNum=spec->vRefNum;
- pbr.fileParam.ioFDirIndex=0;
- pbr.fileParam.ioNamePtr=(StringPtr)spec->name;
- pbr.fileParam.ioDirID=spec->parID;
-
- err=PBHGetFInfo(&pbr,false);
-
- if (err==fnfErr){
- // then the file doesn't exist, but is being put in a default place so it really should be there
- } else if (err!=noErr)
- return err;
-
- if (pbr.fileParam.ioFlRLgLen<=0){
- // file doesn't have a resource fork, create one for the file
- HCreateResFile(spec->vRefNum,spec->parID,spec->name);
- return ResError();
- }
- return noErr;
- }
-
- /*
- ICFindFolder
-
- converted from the pascal wrapper function to call the FindFolder trap.
-
- Was declared as:
-
- inline $7000,$A823
- */
- OSErr ICFindFolder(short vRefNum,OSType folderType,Boolean createFolder,short* foundVRefNum,long* foundDirID){
- return FindFolder(vRefNum,folderType,createFolder,foundVRefNum,foundDirID);
- }
-
- ICError ICRStart(ICRRecordPtr inst,OSType creator){
- ICError err;
- Str255 defPrompt="\pCreate configuration as:";
-
- if (inst==(ICRRecordPtr)0)
- return (ICError)paramErr;
-
- inst->have_config_file=false;
- inst->config_file.vRefNum=0;
- inst->config_file.parID=0;
- inst->config_file.name[0]=0;
- inst->config_refnum=0;
- inst->perm=icNoPerm;
-
- BlockMoveData((Ptr)defPrompt,(Ptr)inst->prompt,defPrompt[0]+2);
-
- ICRDefaultFileName(inst,inst->default_filename);
-
- return noErr;
- }
-
- Boolean ICRCloseIfOpen(ICRRecordPtr inst){
- Boolean ret=inst->perm!=icNoPerm;
-
- if (inst->config_refnum!=0){
- CloseResFile(inst->config_refnum);
- inst->config_refnum=0;
- }
-
- inst->perm=icNoPerm;
-
- return ret;
- }
-
- ICError ICRStop(ICRRecordPtr inst){
-
- if (inst==(ICRRecordPtr)0)
- return (ICError)paramErr;
-
- if (ICRCloseIfOpen(inst))
- return (ICError)paramErr;
-
- return (ICError)noErr;
- }
-
-
- ICError ValidDirSpec(ICDirSpec* folder){
- CInfoPBRec cpb;
-
- cpb.hFileInfo.ioVRefNum=folder->vRefNum;
- cpb.hFileInfo.ioDirID=folder->dirID;
- cpb.hFileInfo.ioNamePtr=(StringPtr)0;
- cpb.hFileInfo.ioFDirIndex=-1;
-
- return (ICError)PBGetCatInfoSync(&cpb);
- }
-
- OSErr FoundFile(ICDirSpec* folder,short ndx,FSSpec* found_file){
- OSErr err;
- CInfoPBRec cpb;
- Boolean is_folder;
- Boolean was_alias;
- long response;
-
- cpb.hFileInfo.ioVRefNum=folder->vRefNum;
- cpb.hFileInfo.ioDirID=folder->dirID;
- cpb.hFileInfo.ioNamePtr=found_file->name;
- cpb.hFileInfo.ioFDirIndex=ndx;
-
- err=PBGetCatInfoSync(&cpb);
-
- if (err==noErr){
- found_file->vRefNum=cpb.hFileInfo.ioVRefNum;
- found_file->parID=cpb.hFileInfo.ioFlParID;
-
- if ((cpb.hFileInfo.ioFlAttrib&(16))||(cpb.hFileInfo.ioFlFndrInfo.fdType!=kICFileType)){
- err=(OSErr)1;
- } else if ((Gestalt(gestaltAliasMgrAttr,&response)==noErr)&&(BitTst(&response,(31-gestaltAliasMgrPresent)))){
- err=ResolveAliasFile(found_file,true,&is_folder,&was_alias);
-
- if (err!=noErr)
- err=(OSErr)1;
- }
- }
-
- return err;
- }
-
- Boolean ScanFolder(ICRRecordPtr inst,ICDirSpec* folder,FSSpecPtr found_file){
- ICError err;
- Boolean found;
- register short i;
-
- BlockMoveData((Ptr)inst->default_filename,(Ptr)found_file->name,inst->default_filename[0]+1);
-
- found=(FoundFile(folder,0,found_file)==noErr);
-
- if (!found){
- i=1;
-
- do {
- found_file->name[0]=0;
- err=FoundFile(folder,i,found_file);
- i++;
- } while (err!=1);
-
- found=(err==noErr);
- }
-
- return found;
- }
-
- ICError ICRFindConfigFile(ICRRecordPtr inst,short count,ICDirSpecArrayPtr folders){
- return ICRGeneralFindConfigFile(inst,true,true,count,folders);
- }
-
- ICError ICRFindUserConfigFile(ICRRecordPtr inst,ICDirSpec* where){
- return ICRGeneralFindConfigFile(inst,false,true,1,where);
- }
-
- OSErr FindPrefFolder(ICDirSpec* pref_fold){
- OSErr err;
- SysEnvRec env;
- long response;
-
- err=Gestalt(gestaltFindFolderAttr,&response);
-
- if (err==noErr){
- if (BitTst(&response,(31-gestaltFindFolderPresent)))
- return ICFindFolder(kOnSystemDisk,kPreferencesFolderType,true,&(pref_fold->vRefNum),&(pref_fold->dirID));
- }
-
- // otherwise simulate FindFolder
-
- err=SysEnvirons(curSysEnvVers,&env);
-
- if (err==noErr)
- err=GetWDInfo(env.sysVRefNum,&(pref_fold->vRefNum),&(pref_fold->dirID),&response);
-
- return err;
- }
-
- ICError ICRGeneralFindConfigFile(ICRRecordPtr inst,Boolean search_prefs,Boolean can_create,short count,ICDirSpecArrayPtr folders){
- ICError err=noErr;
- register short i=0;
- Boolean found=false;
- ICDirSpec pref_fold;
- ICDirSpec* last_folder_scanned;
- FSSpec temp_config_file;
- HParamBlockRec pbr;
-
- inst->have_config_file=false;
-
- if (inst->perm!=icNoPerm)
- return (ICError)paramErr;
-
- if ((count<0)||((count!=0)&&(folders==(ICDirSpecArrayPtr)0)))
- return (ICError)paramErr;
-
- if ((count==0)&&(!search_prefs)&&(can_create))
- return (ICError)paramErr;
-
- i=0;
- while ((err==noErr)&&(i<count)){
- err=ValidDirSpec(&(folders[i]));
- i++;
- }
-
- if (err!=noErr)
- return err;
-
- i=0;
-
- while ((i<count)&&(!found)){
- found=ScanFolder(inst,&(folders[i]),&temp_config_file);
-
- last_folder_scanned=&(folders[i]);
- i++;
- }
-
- if ((!found)&&(search_prefs)){
- err=FindPrefFolder(&pref_fold);
-
- if (err==noErr){
- found=ScanFolder(inst,&pref_fold,&temp_config_file);
- last_folder_scanned=&pref_fold;
- }
- }
-
- if ((!found)&&(can_create)){
- temp_config_file.vRefNum=last_folder_scanned->vRefNum;
- temp_config_file.parID=last_folder_scanned->dirID;
- BlockMoveData((Ptr)inst->default_filename,(Ptr)temp_config_file.name,inst->default_filename[0]+1);
- found=true;
- }
-
- if (!found)
- err=icConfigNotFoundErr;
-
- if (err==noErr){
- BlockMoveData((Ptr)&(temp_config_file),(Ptr)&(inst->config_file),sizeof(FSSpec));
- inst->have_config_file=true;
-
- // Need to ensure that there is a resource fork for a file...
- err=EnsureResourceFork(&(inst->config_file));
- }
-
- return err;
- }
-
- void SetSFCWD(ICRRecordPtr inst){
-
- if (inst->have_config_file){
- LMSetCurDirStore(inst->config_file.parID);
- LMSetSFSaveDisk(-(inst->config_file.vRefNum));
- }
- }
-
- ICError GetFile(ICRRecordPtr inst,FSSpecPtr fs){
- ICError err=userCanceledErr;
- SFTypeList typeList;
- StandardFileReply nreply;
- SFReply oreply;
- long eric;
- Point where;
-
- SetSFCWD(inst);
-
- typeList[0]=kICFileType;
-
- if (HaveNewStandardFile()){
- StandardGetFile((FileFilterUPP)0,1,typeList,&nreply);
- if (nreply.sfGood){
- BlockMoveData((Ptr)&(nreply.sfFile),fs,sizeof(FSSpec));
- err=noErr;
- }
- } else {
- where.h=0x40;
- where.v=0x40;
-
- SFGetFile(where,"\p",(FileFilterUPP)0,1,typeList,(DlgHookUPP)0,&oreply);
- if (oreply.good){
- err=GetWDInfo(oreply.vRefNum,&fs->vRefNum,&fs->parID,&eric);
- BlockMoveData(oreply.fName,fs->name,oreply.fName[0]+1);
- }
- }
-
- return err;
- }
-
- ICError PutFile(ICRRecord* inst,FSSpecPtr fs){
- ICError err;
- SFTypeList typeList;
- StandardFileReply nreply;
- SFReply oreply;
- long eric;
- Str63 defname;
-
- SetSFCWD(inst);
- err=userCanceledErr;
- typeList[0]=kICFileType;
-
- if (inst->have_config_file){
- BlockMoveData(inst->config_file.name,defname,inst->config_file.name[0]+1);
- } else {
- BlockMoveData(inst->default_filename,defname,inst->default_filename[0]+1);
- }
-
- if (HaveNewStandardFile()){
- StandardPutFile(inst->prompt,defname,&nreply);
- if (nreply.sfGood){
- BlockMoveData((Ptr)&(nreply.sfFile),(Ptr)fs,sizeof(FSSpec));
- err=noErr;
- }
- } else {
- Point where;
-
- where.h=0x040;
- where.v=0x040;
-
- SFPutFile(where,inst->prompt,defname,(DlgHookUPP)0,&oreply);
- if (oreply.good){
- err=GetWDInfo(oreply.vRefNum,&fs->vRefNum,&fs->parID,&eric);
- BlockMoveData(oreply.fName,fs->name,oreply.fName[0]+1);
- }
- }
-
- return err;
- }
-
- ICError ICRChooseConfig(ICRRecord* inst){
- OSErr err=noErr;
- FSSpec config;
-
- if (inst->perm!=icNoPerm)
- return paramErr;
-
- err=CanInteract();
-
- if (err==noErr){
- err=GetFile(inst,&config);
- }
-
- if (err==noErr){
- err=ICRSpecifyConfigFile(inst,&config);
- }
-
- return err;
- }
-
- ICError ICRChooseNewConfig(ICRRecord* inst){
- OSErr err=noErr;
- FSSpec config;
-
- if (inst->perm!=icNoPerm)
- return paramErr;
-
- err=CanInteract();
-
- if (err==noErr)
- err=PutFile(inst,&config);
-
- if (err==noErr){
- HDelete(config.vRefNum,config.parID,config.name);
- err=HCreate(config.vRefNum,config.parID,config.name,kICCreator,kICFileType);
- }
-
- if (err==noErr)
- err=ICRSpecifyConfigFile(inst,&config);
-
- return err;
- }
-
- ICError ICRGetConfigName(ICRRecord* inst,Boolean longname,StringPtr name){
- OSErr err=noErr;
-
- if (!inst->have_config_file)
- return paramErr;
-
- if (!longname){
- BlockMoveData(inst->config_file.name,name,inst->config_file.name[0]+1);
- err=noErr;
- } else {
- err=FSSpecToFullPath(&(inst->config_file),name);
- }
-
- return err;
- }
-
- ICError ICRGetConfigReference(ICRRecord* inst,ICConfigRefHandle ref){
- ICError err=noErr;
- ICConfigRef header;
- long loe;
-
- if (!inst->have_config_file)
- return paramErr;
-
- if (ref==(ICConfigRefHandle)0)
- return paramErr;
-
- err=FSSpecToICFileSpec(&(inst->config_file),(ICFileSpecHandle)ref);
-
- if (err==noErr){
- header.manufacturer=kICOurManufacturer;
- loe=Munger((Handle)ref,0,(Ptr)0,0,&header,sizeof(ICConfigRef));
- err=MemError();
- }
-
- if (err!=noErr)
- SetHandleSize((Handle)ref,0);
-
- return err;
- }
-
- ICError ICRSetConfigReference(ICRRecord* inst,ICConfigRefHandle ref,long flags){
- ICError err;
- ICFileSpecHandle filespec;
- long loe;
- FSSpec fs;
-
- if (inst->perm!=icNoPerm)
- return paramErr;
-
- if (ref==(ICConfigRefHandle)0)
- return paramErr;
-
- if (GetHandleSize((Handle)ref)<4)
- return paramErr;
-
- if ((*ref)->manufacturer!=kICOurManufacturer)
- return icConfigInappropriateErr;
-
- if (GetHandleSize((Handle)ref)<(sizeof(ICConfigRef)+sizeof(ICFileSpec)))
- return paramErr;
-
- BlockMoveData((Ptr)ref,(Ptr)&filespec,sizeof(ICFileSpecHandle));
- err=HandToHand((Handle*)(&filespec));
-
- if (err==noErr){
- loe=Munger((Handle)filespec,0,(Ptr)0,sizeof(ICConfigRef),&loe,0);
- err=ICFileSpecToFSSpec(filespec,!(flags&icNoUserInteraction_mask),&fs);
- DisposeHandle((Handle)filespec);
- }
-
- if (err==noErr)
- ICRSpecifyConfigFile(inst,&fs);
-
- return err;
- }
-
- ICError ICRSpecifyConfigFile(ICRRecord* inst,FSSpecPtr config){
- ICError err;
- ICDirSpec folder;
-
- if (inst->perm!=icNoPerm)
- return paramErr;
-
- folder.vRefNum=config->vRefNum;
- folder.dirID=config->parID;
-
- err=ValidDirSpec(&folder);
-
- if (err==noErr)
- BlockMoveData((Ptr)config,(Ptr)&(inst->config_file),sizeof(FSSpec));
-
- inst->have_config_file=(err==noErr);
-
- if (inst->have_config_file){
- // Need to ensure that there is a resource fork for a file...
- err=EnsureResourceFork(&(inst->config_file));
- }
-
- return err;
- }
-
- ICError ICRGetSeed(ICRRecord* inst,long* seed){
- ICError err;
- CInfoPBRec cpb;
-
- *seed=0L;
- err=fnfErr;
-
- if (inst->have_config_file){
- cpb.hFileInfo.ioVRefNum=inst->config_file.vRefNum;
- cpb.hFileInfo.ioDirID=inst->config_file.parID;
- cpb.hFileInfo.ioNamePtr=inst->config_file.name;
- cpb.hFileInfo.ioFDirIndex=0;
-
- err=PBGetCatInfoSync(&cpb);
-
- if (err==noErr)
- *seed=cpb.hFileInfo.ioFlMdDat;
- else if (err==fnfErr)
- err=noErr;
- }
-
- return err;
- }
-
- ICError ICRGetPerm(ICRRecord* inst,ICPerm* perm){
- *perm=inst->perm;
- return noErr;
- }
-
- short ICRPermToFSPerm(ICPerm perm){
- switch (perm){
- case icReadOnlyPerm:
- return fsRdPerm;
- break;
- case icReadWritePerm:
- return fsRdWrPerm;
- break;
- default:
- return 0;
- break;
- }
-
- return 0;
- }
-
- ICError ICRBegin(ICRRecord* inst,ICPerm perm){
- ICError err;
- short ref;
-
- if ((inst->perm!=icNoPerm)||(perm==icNoPerm))
- return paramErr;
-
- if (!inst->have_config_file)
- return bdNamErr;
-
- ref=FSpOpenResFile(&(inst->config_file),ICRPermToFSPerm(perm));
- err=ResError();
-
- if ((err==fnfErr)||(err==eofErr)){
- switch (perm){
- case icReadOnlyPerm:
- ref=0;
- err=noErr;
- break;
- case icReadWritePerm:
- FSpCreate(&(inst->config_file),kICCreator,kICFileType,smSystemScript);
- FSpCreateResFile(&(inst->config_file),kICCreator,kICFileType,smSystemScript);
- ref=FSpOpenResFile(&(inst->config_file),ICRPermToFSPerm(perm));
- err=ResError();
- break;
- }
- }
-
- if (err==noErr){
- inst->config_refnum=ref;
- inst->perm=perm;
- } else {
- if ((err==opWrErr)||(err==permErr)){
- err=icNoMoreWritersErr;
- }
- }
-
- return err;
- }
-
- ICError ICRCheckInside(ICRRecord* inst){
-
- if (inst->perm==icNoPerm)
- return paramErr;
-
- return noErr;
- }
-
- ICError ICRForceInside(ICRRecord* inst,ICPerm perm,Boolean* force_info){
- ICError err;
-
- *force_info=false;
-
- if ((inst->perm==perm)||((inst->perm==icReadWritePerm)&&(perm==icReadOnlyPerm)))
- return noErr;
- else if (inst->perm==icNoPerm){
- err=ICRBegin(inst,perm);
- *force_info=(err==noErr);
- } else
- return icPermErr;
-
- return err;
- }
-
- ICError ICRReleaseInside(ICRRecord* inst,Boolean force_info){
- if (force_info)
- return ICREnd(inst);
-
- return noErr;
- }
-
- ICError ICRGetPref(ICRRecord* inst,StringPtr key,ICAttr* attr,Ptr buf,long* size){
- ICError err,err2;
- long max_size=*size;
- long true_size;
- short old_refnum;
- Handle prefh;
- Boolean force_info;
-
- *size=0L;
- *attr=ICattr_no_change;
- prefh=(Handle)0;
-
- err=ICRForceInside(inst,icReadOnlyPerm,&force_info);
-
- if ((err==noErr)&&(inst->config_refnum==0)){
- err=icPrefNotFoundErr;
- }
-
- if ((err==noErr)&&((key[0]==0)||((max_size<0)&&(buf!=(Ptr)0))))
- err=paramErr;
-
- if (err==noErr){
- old_refnum=CurResFile();
- UseResFile(inst->config_refnum);
- err=ResError();
-
- if (err==noErr){
- prefh=Get1NamedResource(kRes_Code,key);
- err=ResError();
-
- if (prefh==(Handle)0)
- err=icPrefNotFoundErr;
-
- if (err==noErr){
- true_size=GetHandleSize(prefh);
- if (true_size<4)
- err=icPrefDataErr;
- }
-
- if (err==noErr){
- *size=true_size-4;
- *attr=**((long**)prefh);
-
- if ((buf!=(Ptr)0)&&(*size!=0)){
- if (*size>max_size)
- err=icTruncatedErr;
- else
- max_size=*size;
-
- BlockMoveData((Ptr)((*prefh)+sizeof(long)),buf,max_size);
- }
- }
- UseResFile(old_refnum);
- }
- }
-
- if (prefh!=(Handle)0)
- ReleaseResource(prefh);
-
- err2=ICRReleaseInside(inst,force_info);
-
- if (err==noErr)
- err=err2;
-
- return err;
- }
-
- ICError ICRSetPref(ICRRecord* inst,StringPtr key,ICAttr attr,Ptr buf,long size){
- ICError err,err2;
- long old_attr;
- short old_refnum;
- Handle prefh;
- short id;
- Boolean force_info;
-
- prefh=(Handle)0;
- if (buf==(Ptr)0)
- size=0;
-
- err=ICRForceInside(inst,icReadWritePerm,&force_info);
-
- if ((err==noErr)&&(inst->perm!=icReadWritePerm))
- err=icPermErr;
-
- if ((err==noErr)&&(inst->config_refnum==0))
- err=icInternalErr;
-
- if ((err==noErr)&&((key[0]==0)||(size<0)))
- err=paramErr;
-
- if (err==noErr){
- old_refnum=CurResFile();
- UseResFile(inst->config_refnum);
- err=ResError();
- if (err==noErr){
- prefh=Get1NamedResource(kRes_Code,key);
- if ((prefh!=(Handle)0)&&(GetHandleSize(prefh)<4)){
- RmveResource(prefh);
- DisposeHandle(prefh);
- prefh=(Handle)0;
- }
- if (prefh==(Handle)0)
- old_attr=0;
- else
- old_attr=**((long**)prefh);
-
- if (attr==ICattr_no_change)
- attr=old_attr;
-
- if ((old_attr&ICattr_locked_mask)&&(attr&ICattr_locked_mask)&&(buf!=(Ptr)0))
- err=icPermErr;
-
- if (prefh==(Handle)0){
- prefh=NewHandle(size+4);
- err=MemError();
-
- if (err==noErr){
- do {
- id=Unique1ID(kRes_Code);
- } while (id<=127);
-
- AddResource(prefh,kRes_Code,id,key);
- err=ResError();
-
- if (err!=noErr){
- DisposeHandle(prefh);
- prefh=(Handle)0;
- }
- }
- }
- if ((err==noErr)&&(buf!=(Ptr)0)){
- SetHandleSize(prefh,size+4);
- err=MemError();
- }
- if ((err==noErr)&&(size>0))
- BlockMoveData(buf,(Ptr)((*prefh)+4),size);
- if (err==noErr){
- **((long**)prefh)=attr;
- ChangedResource(prefh);
- WriteResource(prefh);
- err=ResError();
- }
- UseResFile(old_refnum);
- }
- }
-
- if (prefh!=(Handle)0)
- ReleaseResource(prefh);
-
- err2=ICRReleaseInside(inst,force_info);
-
- if (err==noErr)
- err=err2;
-
- return err;
- }
-
- // I call ICRForceInside to speed this routine up. ICRForceInside will do an ICRBegin and hence open the resource
- // file, which is good because otherwise I'd open it twice, once for each ICRGetPref.
-
- ICError ICRFindPrefHandle(ICRRecord* inst,StringPtr key,ICAttr* attr,Handle prefh){
- ICError err=noErr,err2=noErr;
- long prefsize=0L;
- Boolean force_info;
-
- if (prefh==(Handle)0)
- err=paramErr;
-
- if (err==noErr){
- err=ICRForceInside(inst,icReadOnlyPerm,&force_info);
- if (err==noErr)
- err=ICRGetPref(inst,key,attr,(Ptr)0,&prefsize);
-
- if (err==noErr){
- SetHandleSize(prefh,prefsize);
- err=MemError();
- }
-
- if (err==noErr){
- HLock(prefh);
- err=ICRGetPref(inst,key,attr,*prefh,&prefsize);
- HUnlock(prefh);
- }
-
- err2=ICRReleaseInside(inst,force_info);
- }
- if (err==noErr)
- err=err2;
-
- if ((prefh!=(Handle)0)&&(err!=noErr)){
- SetHandleSize(prefh,0);
- }
-
- return err;
- }
-
- ICError ICRGetPrefHandle(ICRRecord* inst,StringPtr key,ICAttr* attr,Handle* prefh){
- ICError err;
-
- *prefh=NewHandle(0);
- err=MemError();
-
- if (err==noErr)
- err=ICRFindPrefHandle(inst,key,attr,*prefh);
-
- if (err==icPrefNotFoundErr){
- SetHandleSize(*prefh,0);
- *attr=0;
- err=noErr;
- }
-
- return err;
- }
-
- ICError ICRSetPrefHandle(ICRRecord* inst,StringPtr key,ICAttr attr,Handle prefh){
- ICError err=noErr;
- SignedByte s;
-
- if (prefh!=(Handle)0){
- if (*prefh==(Ptr)0)
- err=paramErr;
- if (err==noErr){
- s=HGetState(prefh);
- HLock(prefh);
- err=ICRSetPref(inst,key,attr,*prefh,GetHandleSize(prefh));
- HSetState(prefh,s);
- }
- } else {
- err=ICRSetPref(inst,key,attr,(Ptr)0,0);
- }
-
- return err;
- }
-
- ICError ICRCountPref(ICRRecord* inst,long* count){
- ICError err;
- short old_refnum;
-
- err=ICRCheckInside(inst);
- if (err==noErr){
- if (inst->config_refnum==0)
- *count=0;
- else {
- old_refnum=CurResFile();
- UseResFile(inst->config_refnum);
- err=ResError();
- if (err==noErr){
- *count=Count1Resources(kRes_Code);
- err=ResError();
- UseResFile(old_refnum);
- }
- }
- }
-
- if (err!=noErr)
- *count=0;
-
- return err;
- }
-
- ICError ICRGetIndPref(ICRRecord* inst,long n,StringPtr key){
- ICError err;
- short old_refnum;
- Handle prefh=(Handle)0;
- short junk_id;
- ResType junk_type;
-
- err=ICRCheckInside(inst);
- if ((err==noErr)&&(n<1))
- err=paramErr;
-
- if (err==noErr){
- if (inst->config_refnum==0)
- err=icPrefNotFoundErr;
- else {
- old_refnum=CurResFile();
- UseResFile(inst->config_refnum);
- err=ResError();
- if (err==noErr){
- SetResLoad(false);
- prefh=Get1IndResource(kRes_Code,n);
- SetResLoad(true);
-
- if (prefh==(Handle)0)
- err=icPrefNotFoundErr;
- else {
- GetResInfo(prefh,&junk_id,&junk_type,key);
- err=ResError();
- }
- UseResFile(old_refnum);
- }
- }
- }
-
- if (prefh!=(Handle)0)
- ReleaseResource(prefh);
-
- return err;
- }
-
- ICError ICRDeletePref(ICRRecord* inst,StringPtr key){
- ICError err;
- Handle prefh;
- short old_refnum;
-
- err=ICRCheckInside(inst);
- if ((err==noErr)&&(key[0]==0))
- err=paramErr;
-
- if (err==noErr){
- if (inst->config_refnum==0)
- err=icPrefNotFoundErr;
- else {
- old_refnum=CurResFile();
- UseResFile(inst->config_refnum);
- err=ResError();
- if (err==noErr){
- SetResLoad(false);
- prefh=Get1NamedResource(kRes_Code,key);
- err=ResError();
- SetResLoad(true);
- if (prefh==(Handle)0)
- err=icPrefNotFoundErr;
- else {
- RmveResource(prefh);
- DisposeHandle(prefh);
- err=ResError();
- }
- UseResFile(old_refnum);
- }
- }
- }
-
- return err;
- }
-
- ICError ICREnd(ICRRecord* inst){
- ICError err;
-
- err=ICRCheckInside(inst);
- ICRCloseIfOpen(inst);
-
- return err;
- }
-
- ICError ICRDefaultFileName(ICRRecord* inst,StringPtr name){
- Str63 lname=kICDefaultFileName;
-
- BlockMoveData(lname,name,lname[0]+1);
-
- return noErr;
- }
-
- ICError ICREditPreferences(ICRRecord* inst,StringPtr key){
- ICError err;
-
- if (!inst->have_config_file)
- return bdNamErr;
-
- return EditPreferences(key,&(inst->config_file));
- }
-
- /*
- URL Parsing Algorithm
-
- 1. if there is a selection skip to step 4
- 2. expand selection to end of word (never skip an angle bracket though)
- 3. if either end has an angle bracket then expand other end to search for angle bracket
- 4. strip trailing and leading whitespace
- 5. strip whitespace CR whitespace
- 6. off < > if necessary
- 7. remove leading URL:
- 8. extract protocol by looking forwards for :
- 9. if no protocol then prepend "hint:"
- */
-
- Boolean __URL_SpecStartChar(char ch){
- switch (ch){
- case ' ':
- case '<':
- case 9:
- case 13:
- return true;
- default:
- return false;
- }
- }
-
- Boolean __URL_SpecEndChar(char ch){
- switch (ch){
- case ' ':
- case '>':
- case 9:
- case 13:
- return true;
- default:
- return false;
- }
- }
-
- ICError ExpandSelection(char* datap,long len,long* selStart,long* selEnd){
- ICError err=noErr;
- Boolean found;
-
- // expand leading selection backwards looking for word break
- while ((*selStart>0)&&(!__URL_SpecStartChar(datap[(*selStart)-1])))
- (*selStart)--;
- if ((*selStart>0)&&(datap[(*selStart)-1]=='<'))
- (*selStart)--;
-
- // expand trailing selection forwards looking for word break
- while ((*selEnd<len)&&(!__URL_SpecEndChar(datap[*selEnd])))
- (*selEnd)++;
- if ((*selEnd<len)&&(datap[*selEnd]=='>'))
- (*selEnd)++;
-
- // if first char was a < then expand trailing selection to meet matching >
- if ((datap[*selStart]=='<')&&(datap[(*selEnd)-1]!='>')){
- while ((datap[(*selEnd)-1]!='>')&&((*selEnd)-1<=len))
- (*selEnd)++;
-
- // now either a match or at end of len
- if (datap[(*selEnd)-1]!='>')
- return icNoURLErr;
- }
-
- // if last char was a > then expand leading selection to meet matching <
- if ((datap[*selEnd]=='>')&&(datap[*selStart]!='<')){
- while ((datap[*selStart]!='<')&&(*selStart>=0))
- (*selStart)--;
-
- // now either a match or at end of len
- if (datap[*selStart]!='<')
- return icNoURLErr;
- }
-
- return err;
- }
-
- Boolean SpaceTab(char ch){
- if ((ch==' ')||(ch==9))
- return true;
- return false;
- }
-
- Boolean SpaceTabRet(char ch){
- if (ch==13)
- return true;
- return SpaceTab(ch);
- }
-
- ICError ShrinkSelection(char* datap,long len,long* selStart,long* selEnd){
- if (SpaceTab(datap[*selStart]))
- while (SpaceTab(datap[*selStart]))
- (*selStart)++;
- if (SpaceTab(datap[(*selEnd)-1]))
- while (SpaceTab(datap[(*selEnd)-1]))
- (*selEnd)--;
-
- return noErr;
- }
-
- ICError StripReturns(Handle urlh){
- ICError err;
- long srcsize,srcndx,dstndx;
- char* buf;
- SignedByte s;
-
- srcsize=GetHandleSize(urlh);
- err=MemError();
- if (srcsize==0){
- if (err!=noErr)
- return err;
-
- return icNoURLErr;
- }
-
- srcndx=0;
- dstndx=0;
-
- s=HGetState(urlh);
- HLock(urlh);
- buf=(char*)(*urlh);
-
- // skip down the buffer copying src to dst except when meeting cr
- while (srcndx<srcsize){
- if (buf[srcndx]==13){
- // move dstndx back to point to previous non-whitespace
- while ((dstndx>0)&&(SpaceTab(buf[dstndx-1])))
- dstndx--;
- // move srcndx forwards to next non-whitespace
- while ((srcndx<srcsize)&&(SpaceTabRet(buf[srcndx])))
- srcndx++;
- }
-
- if (srcndx<srcsize){
- // copy byte from src to dest
- buf[dstndx]=buf[srcndx];
- srcndx++;
- dstndx++;
- }
- }
-
- HSetState(urlh,s);
-
- // resize the handle to the number of bytes that we copied
- SetHandleSize(urlh,dstndx);
- err=MemError();
-
- return err;
- }
-
- ICError ICRParseURL(ICRRecord* inst,StringPtr hint,Ptr data,long len,long* selStart,long* selEnd,Handle urlh){
- char* datap=(char*)data;
- Str31 tmp="\pURL:";
- long junklong;
- long ndx;
- ICError err=noErr;
-
- if ((data==(Ptr)0)||(urlh==(Handle)0)||(*urlh==(Ptr)0)||(len<=0)||(*selStart<0)||(*selEnd<0)||(*selStart>len)||(*selEnd>len)||(*selStart>*selEnd))
- return paramErr;
-
- if (*selStart==*selEnd)
- err=ExpandSelection(datap,len,selStart,selEnd);
- if (err==noErr) // remove leading and trailing whitespace
- err=ShrinkSelection(datap,len,selStart,selEnd);
-
- if ((err==noErr)&&(*selStart>=*selEnd))
- return icNoURLErr;
-
- err=PtrToXHand((Ptr)&(datap[*selStart]),urlh,(*selEnd)-(*selStart));
- if (err==noErr)
- err=StripReturns(urlh);
-
- if (err==noErr){
- // strip any enclosing < >
- char* buf;
- long bsize=GetHandleSize(urlh);
- SignedByte s=HGetState(urlh);
- Boolean doTrim=false;
-
- HLock(urlh);
- buf=(char*)(*urlh);
-
- if ((buf[0]=='<')&&(buf[bsize-1]=='>')){
- doTrim=true;
- }
-
- HSetState(urlh,s);
-
- if (doTrim){
- SetHandleSize(urlh,bsize-1);
- HUnlock(urlh);
- // unlock before the munger call
- Munger(urlh,0,(Ptr)0,1,(Ptr)-1,0);
- HSetState(urlh,s);
- }
-
- // trim off leading "\pURL:"
- HLock(urlh);
- if ((GetHandleSize(urlh)>tmp[0])&&(IUMagIDString(*urlh,&(tmp[1]),tmp[0],tmp[0])==0)){
- HUnlock(urlh);
- Munger(urlh,0,(Ptr)0,tmp[0],(Ptr)-1,0);
- }
- HSetState(urlh,s);
-
- // search for protocol
- tmp[0]=1;tmp[1]=':';
- HUnlock(urlh);
- ndx=Munger(urlh,0,&(tmp[1]),1,(Ptr)0,0);
- if ((ndx<0)||(ndx>255)){
- // failed to find a colon in first 256 bytes,prepend "hint:" to url
- if (hint[0]==0)
- err=icNoURLErr;
- else {
- Munger(urlh,0,(Ptr)0,0,&(hint[1]),hint[0]);
- err=MemError();
- }
- }
- HSetState(urlh,s);
- }
- return err;
- }
-
- ICError ICRLaunchURL(ICRRecord* inst,StringPtr hint,Ptr data,long len,long* selStart,long* selEnd){
- ICError err;
- Handle urlh;
- ICAppSpec helper;
- Str255 scheme;
- Str255 temp=kICHelper;
- long junk_attr;
- long size;
-
- urlh=NewHandle(0);
- err=MemError();
-
- if (err==noErr)
- err=ICRParseURL(inst,hint,data,len,selStart,selEnd,urlh);
- else
- urlh=(Handle)0;
-
- if (err==noErr)
- err=FindScheme(urlh,scheme);
-
- if (err==noErr){
- size=sizeof(ICAppSpec);
- BlockMoveData(scheme,(Ptr)&(temp[temp[0]+1]),scheme[0]);
- temp[0]+=scheme[0];
- err=ICRGetPref(inst,temp,&junk_attr,(Ptr)(&helper),&size);
- }
-
- if (err==noErr)
- err=LaunchURL(helper.fCreator,urlh);
-
- if (urlh!=(Handle)0)
- DisposeHandle(urlh);
-
- return err;
- }
-
- void UnpackCopyString(Ptr* p,StringPtr s){
- short len;
-
- // calc the len of the current pascal string pointed to by p
- len=((**p) & 0x00ff) +1;
-
- // copy the string in the buffer to s
- BlockMoveData(*p,s,len);
-
- // move the pointer to the start of the next pascal string
- *p=(Ptr)((*p)+len);
- }
-
- // Internal Mapping Subs
- OSErr UnpackEntry(Handle entries,long pos,ICMapEntry* entry,long* user_length){
- // WARNING: Depends very much on the exact format of ICMapEntry!
- Ptr org,p;
- long maxsize;
- OSErr err=noErr;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(pos<0)||(pos>GetHandleSize(entries)-6))
- return paramErr;
-
- p=(Ptr)((*entries)+pos);
- maxsize=GetHandleSize(entries);
- org=p;
-
- BlockMoveData(p,(Ptr)entry,6);
-
- if ((entry->fixed_length!=ICmap_fixed_length)||(entry->fixed_length>entry->total_length)||(entry->total_length>maxsize))
- return badExtResource;
-
- BlockMoveData(p,entry,entry->fixed_length);
- p=(Ptr)(p+entry->fixed_length);
- UnpackCopyString(&p,entry->extension);
- UnpackCopyString(&p,entry->creator_app_name);
- UnpackCopyString(&p,entry->post_app_name);
- UnpackCopyString(&p,entry->MIME_type);
- UnpackCopyString(&p,entry->entry_name);
-
- *user_length=entry->total_length-(p-org);
-
- return err;
- }
-
- // a fast version of ICRGetEntry doesn't return all of the strings for the entry
- // WARNING: Depends very much on the exact format of ICMapEntry!
- OSErr FastGetEntry(Handle entries,long pos,ICMapEntry* entry){
- Ptr org,p;
- long maxsize;
- OSErr err=noErr;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(pos<0)||(pos>GetHandleSize(entries)-6))
- return paramErr;
-
- p=(Ptr)((*entries)+pos);
- maxsize=GetHandleSize(entries);
- BlockMoveData(p,entry,6);
-
- if ((entry->fixed_length!=ICmap_fixed_length)||(entry->fixed_length>entry->total_length)||(entry->total_length>maxsize))
- return badExtResource;
-
- BlockMoveData(p,entry,entry->fixed_length);
- p=(Ptr)(p+entry->fixed_length);
- BlockMoveData(p,entry->extension,(((*p)&0x00ff)+1));
- return err;
- }
-
- void PackCopyString(ICMapEntry* entry,Ptr p,StringPtr s){
-
- BlockMoveData(s,(Ptr)(p+entry->total_length),s[0]+1);
- entry->total_length+=s[0]+1;
- }
-
- void PackEntry(ICMapEntry* entry,Ptr p,long user_length){
- Ptr a,b;
-
- entry->version=0;
-
- a=(Ptr)&(entry->extension);
- b=(Ptr)entry;
-
- entry->fixed_length=a-b;
- entry->total_length=entry->fixed_length;
-
- PackCopyString(entry,p,entry->extension);
- PackCopyString(entry,p,entry->creator_app_name);
- PackCopyString(entry,p,entry->post_app_name);
- PackCopyString(entry,p,entry->MIME_type);
- PackCopyString(entry,p,entry->entry_name);
-
- entry->total_length+=user_length;
-
- BlockMoveData(entry,p,entry->fixed_length);
- }
-
- short GetShort(Ptr P){
- unsigned char* p=(unsigned char*)P;
- short val=0;
-
- val=p[0];
- val <<= 8;
- val+=p[1];
-
- return val;
- }
-
- char UpCase(char ch){
-
- if ((ch>='a')&&(ch<='z'))
- return (ch-'a')+'A';
-
- return ch;
- }
-
- Boolean IsExtensionVar(StringPtr name,StringPtr ext){
- short pn,pe;
-
- if (name[0]>=ext[0]){
- pn=name[0]-ext[0]+1;
- pe=1;
-
- while (pe<=ext[0]){
- if (UpCase(name[pn])!=UpCase(ext[pe]))
- break;
-
- pn++;
- pe++;
- }
-
- return pe>ext[0];
- }
- return false;
- }
-
- // Low Level Mapping Routines
-
- ICError ICRCountMapEntries(ICRRecord* inst,Handle entries,long* count){
- Ptr p;
- long pos;
- short size;
- long hsize;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0))
- return paramErr;
-
- p=*entries;
- pos=0L;
- *count=0;
- hsize=GetHandleSize(entries);
- while (pos<hsize){
- size=GetShort(p); // extract the total_length value from the current pointer
- pos+=size; // add it to the pos offset
- p+=size; // add it to the pointer
- (*count)++; // increment the count
- }
-
- return noErr;
- }
-
- ICError ICRGetIndMapEntry(ICRRecord* inst,Handle entries,long ndx,long* pos,ICMapEntry* entry){
- ICError err;
- Ptr p;
- long i;
- short size;
- long hsize;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(ndx<0))
- return paramErr;
-
- p=(Ptr)*entries;
- *pos=0;
- hsize=GetHandleSize(entries);
-
- while ((ndx>1)&&(*pos<hsize)){
- size=GetShort(p); // extract the total_length value from the current pointer
- *pos+=size; // add the size to the pos offset
- p+=size; // add the size to the pointer
- ndx--; // decrease the index for the entry
- }
-
- return ICRGetMapEntry(inst,entries,*pos,entry);
- }
-
- ICError ICRGetMapEntry(ICRRecord* inst,Handle entries,long pos,ICMapEntry* entry){
- ICError err;
- long user_length;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(pos<0)||(pos>GetHandleSize(entries)))
- return paramErr;
-
- return UnpackEntry(entries,pos,entry,&user_length);
- }
-
- ICError ICRSetMapEntry(ICRRecord* inst,Handle entries,long pos,ICMapEntry* entry){
- ICError err;
- ICMapEntry e,oldentry;
- long user_length,source_length;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(pos<0)||(pos>GetHandleSize(entries)))
- return paramErr;
-
- err=UnpackEntry(entries,pos,&oldentry,&user_length);
-
- if (err==noErr){
- PackEntry(entry,(Ptr)&e,user_length);
- source_length=oldentry.total_length-user_length;
-
- if (user_length<8){ // hack to remove alignment bytes from previous version
- source_length=oldentry.total_length;
- e.total_length=e.total_length-user_length;
- user_length=0;
- }
- Munger(entries,pos,(Ptr)0,source_length,&e,e.total_length-user_length);
- err=MemError();
- }
-
- return err;
- }
-
- ICError ICRDeleteMapEntry(ICRRecord* inst,Handle entries,long pos){
- ICError err;
- ICMapEntry entry;
- long user_length;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(pos<0)||(pos>=GetHandleSize(entries)))
- return paramErr;
-
- err=UnpackEntry(entries,pos,&entry,&user_length);
-
- if (err==noErr){
- Munger(entries,pos,(Ptr)0,entry.total_length,(Ptr)-1,0);
- err=MemError();
- }
-
- return err;
- }
-
- ICError ICRAddMapEntry(ICRRecord* inst,Handle entries,ICMapEntry* entry){
- ICError err;
- ICMapEntry tmp_entry;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0))
- return paramErr;
-
- PackEntry(entry,(Ptr)&tmp_entry,0);
-
- return PtrAndHand(&tmp_entry,entries,entry->total_length);
- }
-
- // High Level Mapping Subs
-
- ICError ICRMapEntriesFilename(ICRRecord* inst,Handle entries,StringPtr filename,ICMapEntry* entry){
- // Implementation lifted directly from Space Aliens
- ICError err;
- short longest_len;
- long posndx,found_pos;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0)||(filename[0]==0))
- return paramErr;
-
- // loop through the entries
- // looking for the longest match
-
- longest_len=0;
- posndx=0;
-
- while (FastGetEntry(entries,posndx,entry)==noErr){
- // the entry matches if not_incoming flag bit is clear,
- // it's longer than the previous match, it's longer than the filename,
- // and it matches the last N chars of the filename.
-
- if ((entry->extension[0]>longest_len)&&(!(entry->flags&ICmap_not_incoming_mask))&&(IsExtensionVar(filename,entry->extension))){
- // record the new longest entry
- found_pos=posndx;
- longest_len=entry->extension[0];
- }
- // increment posndx so that we get the next entry the next time around the loop
- posndx+=entry->total_length;
- }
-
- if (longest_len==0)
- return icPrefNotFoundErr;
-
- return ICRGetMapEntry(inst,entries,found_pos,entry);
- }
-
- ICError ICRMapEntriesTypeCreator(ICRRecord* inst,Handle entries,OSType fType,OSType fCreator,StringPtr filename,ICMapEntry* entry){
- ICError err;
- long posndx,found_pos,match_weight,best_weight;
-
- if ((entries==(Handle)0)||(*entries==(Ptr)0))
- return paramErr;
-
- posndx=0L;
- best_weight=-1L;
-
- while (FastGetEntry(entries,posndx,entry)==noErr){
- if (!(entry->flags&ICmap_not_outgoing_mask)){
- if (entry->file_type==fType){
- match_weight=entry->file_creator==fCreator;
- if (IsExtensionVar(filename,entry->extension)){
- match_weight+=2*(entry->extension[0]);
- }
- if (match_weight>best_weight){
- // record the new longest entry
- found_pos=posndx;
- best_weight=match_weight;
- }
- }
- }
- posndx+=entry->total_length;
- }
-
- if (best_weight==-1)
- return icPrefNotFoundErr;
-
- return ICRGetMapEntry(inst,entries,found_pos,entry);
- }
-
- // High Level Mapping Routines
-
- ICError ICRMapFilename(ICRRecord* inst,StringPtr filename,ICMapEntry* entry){
- ICError err;
- Handle entries;
- ICAttr junk_attr;
-
- if (filename[0]==0)
- return paramErr;
-
- err=ICRGetPrefHandle(inst,kICMapping,&junk_attr,&entries);
- if (err==noErr){
- err=ICRMapEntriesFilename(inst,entries,filename,entry);
- DisposeHandle(entries);
- }
-
- return err;
- }
-
- ICError ICRMapTypeCreator(ICRRecord* inst,OSType fType,OSType fCreator,StringPtr filename,ICMapEntry* entry){
- ICError err;
- Handle entries;
- ICAttr junk_attr;
-
- err=ICRGetPrefHandle(inst,kICMapping,&junk_attr,&entries);
- if (err==noErr){
- err=ICRMapEntriesTypeCreator(inst,entries,fType,fCreator,filename,entry);
- DisposeHandle(entries);
- }
-
- return err;
- }
-
-
-
-
-
-
-
-
-
-
-